#!/bin/sh
#
# This is the script for generating files for a specific Dalton test job.
#
# For the .check file ksh or bash is preferred, otherwise use sh
# (and hope it is not the old Bourne shell, which will not work)
#
if [ -x /bin/ksh ]; then
   CHECK_SHELL='#!/bin/ksh'
elif [ -x /bin/bash ]; then
   CHECK_SHELL='#!/bin/bash'
else
   CHECK_SHELL='#!/bin/sh'
fi

#######################################################################
#  TEST DESCRIPTION
#######################################################################
cat > vibave_spinspin.info <<'%EOF%'
   vibave_spinspin
   ---------------
   Molecule:         H2O
   Wave Function:    HF / STO-3G
   Test Purpose:     Vibrational average of indirect spin-spin couplings 
                     for H2O^{18}
%EOF%

#######################################################################
#  MOLECULE INPUT
#######################################################################
cat > vibave_spinspin.mol <<'%EOF%'
BASIS
STO-3G
H2O

Atomtypes=2
Atoms=1 Charge=8.0
O     0.0000000000        0.0000000000       -0.8009956615 Isotope=18
Charge=1.0 Atoms=2
H     0.0000000000        1.4325641791        0.4004978308
H     0.0000000000       -1.4325641791        0.4004978308
%EOF%

#######################################################################
#  DALTON INPUT
#######################################################################
cat > vibave_spinspin.dal <<'%EOF%'
**DALTON INPUT
.NMDDRV
**NMDDRV
.SYMMETRY
  C2v
.VIBANA
.DISPLA
 0.01
*PROPAV
.ANHA-P
**WAVE FUNCTIONS
.HF
*SCF INPUT
.THRESH
 1.0D-12
**EACH STEP
.SPIN-SPIN
*SPIN-S
.SELECT
  3
  1  2  3
*TRPRSP
.THRESH
1.0D-12
*LINRES
.THRESH
1.0D-12
**END OF DALTON INPUT
%EOF%
#######################################################################



#######################################################################

#######################################################################
#  CHECK SCRIPT
#######################################################################
echo $CHECK_SHELL >vibave_spinspin.check
cat >>vibave_spinspin.check <<'%EOF%'
log=$1

if [ `uname` = Linux ]; then
   GREP="egrep -a"
else
   GREP="egrep"
fi

# Starting energy!
CRIT1=`$GREP "Final * HF energy\: * \-74\.96590119277" $log | wc -l`
CRIT2=`$GREP "Electronic energy\: * \-83\.87238874744" $log | wc -l`
TEST[1]=`expr	$CRIT1 \+ $CRIT2`
CTRL[1]=6
ERROR[1]="STARTING ENERGY NOT CORRECT"

# Symmetry
CRIT1=`$GREP "1\. irep\:" $log | wc -l`
CRIT2=`$GREP "1\.00 * 1\.00 * 1\.00 * 1\.00" $log | wc -l`
CRIT3=`$GREP "2\. irep\:" $log | wc -l`
CRIT4=`$GREP "1\.00 \-1\.00 * 1\.00 \-1\.00" $log | wc -l`
CRIT5=`$GREP "3\. irep\:" $log | wc -l`
CRIT6=`$GREP "1\.00 * 1\.00 \-1\.00 \-1\.00" $log | wc -l`
CRIT7=`$GREP "4\. irep\:" $log | wc -l`
CRIT8=`$GREP "1\.00 \-1\.00 \-1\.00 * 1\.00" $log | wc -l`
TEST[2]=`expr	$CRIT1 \+ $CRIT2 \+ $CRIT3 \+ $CRIT4 \+ $CRIT5 \+ $CRIT6 \+ \
		$CRIT7 \+ $CRIT8`
CTRL[2]=12
ERROR[2]="SYMMETRY NOT CORRECT"

# isotopes, harm. frequencies, 
CRIT1=`$GREP "O * 17\.999159" $log | wc -l`
CRIT2=`$GREP "H *_1 * 1\.007825" $log | wc -l`
CRIT3=`$GREP "H *_2 * 1\.007825" $log | wc -l`
CRIT4=`$GREP "1 * 4130\.[0-9][0-9] * (0| )\.0188[0-9][0-9]" $log | wc -l`
CRIT5=`$GREP "1 * 2161\.[0-9][0-9] * (0| )\.0098[0-9][0-9]" $log | wc -l`
CRIT6=`$GREP "4 * 4374\.[0-9][0-9] * (0| )\.0199[0-9][0-9]" $log | wc -l`
TEST[3]=`expr	$CRIT1 \+ $CRIT2 \+ $CRIT3 \+ $CRIT4 \+ $CRIT5 \+ $CRIT6`
CTRL[3]=9
ERROR[3]="ISOTOPES/HARM. FREQ. NOT CORRECT"

# Spin-spin average
CRIT1=`$GREP "Isotropic coupling * \: * 12\.11[0-9][0-9][0-9][0-9] Hz" $log | wc -l`
CRIT2=`$GREP "Anisotropic coupling * \: * \-63\.78[0-9][0-9][0-9][0-9] Hz" $log | wc -l`
CRIT3=`$GREP "Asymmetry * \: * (0| )\.41[0-9][0-9][0-9][0-9]" $log | wc -l`
CRIT4=`$GREP "S parameter * \: * \-65\.61[0-9][0-9][0-9][0-9] Hz" $log | wc -l`
CRIT5=`$GREP "A parameter * \: * (\-0| \-)\.22[0-9][0-9][0-9][0-9] Hz" $log | wc -l`
CRIT6=`$GREP "Isotropic DSO contribution\: * (\-0| \-)\.49[0-9][0-9][0-9][0-9] Hz" $log | wc -l`
CRIT7=`$GREP "Isotropic PSO contribution\: * \-4\.59[0-9][0-9][0-9][0-9] Hz" $log | wc -l`
CRIT8=`$GREP "Isotropic SD contribution \: * 1\.53[0-9][0-9][0-9][0-9] Hz" $log | wc -l`
CRIT9=`$GREP "Isotropic FC contribution \: * 15\.67[0-9][0-9][0-9][0-9] Hz" $log | wc -l`
CRIT10=`$GREP "Isotropic coupling * \: * \-31\.94[0-9][0-9][0-9][0-9] Hz" $log | wc -l`
CRIT11=`$GREP "Anisotropic coupling * \: * \-55\.59[0-9][0-9][0-9][0-9] Hz" $log | wc -l`
CRIT12=`$GREP "Asymmetry * \: * (\-0| \-)\.46[0-9][0-9][0-9][0-9]" $log | wc -l`
CRIT13=`$GREP "S parameter * \: * 57\.53[0-9][0-9][0-9][0-9] Hz" $log | wc -l`
CRIT14=`$GREP "A parameter * \: * 1(0| )\.34[0-9][0-9][0-9][0-9] Hz" $log | wc -l`
CRIT15=`$GREP "Isotropic DSO contribution\: * \-4\.70[0-9][0-9][0-9][0-9] Hz" $log | wc -l`
CRIT16=`$GREP "Isotropic PSO contribution\: * 3\.04[0-9][0-9][0-9][0-9] Hz" $log | wc -l`
CRIT17=`$GREP "Isotropic SD contribution \: * 1\.24[0-9][0-9][0-9][0-9] Hz" $log | wc -l`
CRIT18=`$GREP "Isotropic FC contribution \: * \-31\.52[0-9][0-9][0-9][0-9] Hz" $log | wc -l`
CRIT19=`$GREP "Isotropic coupling * \: * 1\.46[0-9][0-9][0-9][0-9] Hz" $log | wc -l`
CRIT20=`$GREP "Anisotropic coupling * \: * \-4\.27[0-9][0-9][0-9][0-9] Hz" $log | wc -l`
CRIT21=`$GREP "Asymmetry * \: * (0| )\.19[0-9][0-9][0-9][0-9]" $log | wc -l`
CRIT22=`$GREP "S parameter * \: * \-4\.30[0-9][0-9][0-9][0-9] Hz" $log | wc -l`
CRIT23=`$GREP "A parameter * \: * (\-0| \-)\.03[0-9][0-9][0-9][0-9] Hz" $log | wc -l`
CRIT24=`$GREP "Isotropic DSO contribution\: * (\-0| \-)\.01[0-9][0-9][0-9][0-9] Hz" $log | wc -l`
CRIT25=`$GREP "Isotropic PSO contribution\: * (\-0| \-)\.00[0-9][0-9][0-9][0-9] Hz" $log | wc -l`
CRIT26=`$GREP "Isotropic SD contribution \: * (0| )\.02[0-9][0-9][0-9][0-9] Hz" $log | wc -l`
CRIT27=`$GREP "Isotropic FC contribution \: * 1\.46[0-9][0-9][0-9][0-9] Hz" $log | wc -l`
CRIT28=`$GREP "Isotropic coupling * \: * \-3\.71[0-9][0-9][0-9][0-9] Hz" $log | wc -l`
CRIT29=`$GREP "Anisotropic coupling * \: * \-3\.00[0-9][0-9][0-9][0-9] Hz" $log | wc -l`
CRIT30=`$GREP "Asymmetry * \: * (\-0| \-)\.19[0-9][0-9][0-9][0-9]" $log | wc -l`
CRIT31=`$GREP "S parameter * \: * 3\.02[0-9][0-9][0-9][0-9] Hz" $log | wc -l`
CRIT32=`$GREP "A parameter * \: * (0| )\.04[0-9][0-9][0-9][0-9] Hz" $log | wc -l`
CRIT33=`$GREP "Isotropic DSO contribution\: * (0| )\.03[0-9][0-9][0-9][0-9] Hz" $log | wc -l`
CRIT34=`$GREP "Isotropic PSO contribution\: * (\-0| \-)\.03[0-9][0-9][0-9][0-9] Hz" $log | wc -l`
CRIT35=`$GREP "Isotropic SD contribution \: * (0| )\.00[0-9][0-9][0-9][0-9] Hz" $log | wc -l`
CRIT36=`$GREP "Isotropic FC contribution \: * \-3\.71[0-9][0-9][0-9][0-9] Hz" $log | wc -l`
CRIT37=`$GREP "Isotropic coupling * \: * 2\.93[0-9][0-9][0-9][0-9] Hz" $log | wc -l`
CRIT38=`$GREP "Anisotropic coupling * \: * \-3\.29[0-9][0-9][0-9][0-9] Hz" $log | wc -l`
CRIT39=`$GREP "Asymmetry * \: * (0| )\.08[0-9][0-9][0-9][0-9]" $log | wc -l`
CRIT40=`$GREP "S parameter * \: * \-3\.30[0-9][0-9][0-9][0-9] Hz" $log | wc -l`
CRIT41=`$GREP "A parameter * \: * (\-0| \-)\.01[0-9][0-9][0-9][0-9] Hz" $log | wc -l`
CRIT42=`$GREP "Isotropic DSO contribution\: * (0| )\.02[0-9][0-9][0-9][0-9] Hz" $log | wc -l`
CRIT43=`$GREP "Isotropic PSO contribution\: * (0| )\.11[0-9][0-9][0-9][0-9] Hz" $log | wc -l`
CRIT44=`$GREP "Isotropic SD contribution \: * (0| )\.06[0-9][0-9][0-9][0-9] Hz" $log | wc -l`
CRIT45=`$GREP "Isotropic FC contribution \: * 2\.72[0-9][0-9][0-9][0-9] Hz" $log | wc -l`
CRIT46=`$GREP "Isotropic coupling * \: * \-1\.67[0-9][0-9][0-9][0-9] Hz" $log | wc -l`
CRIT47=`$GREP "Anisotropic coupling * \: * (0| )\.95[0-9][0-9][0-9][0-9] Hz" $log | wc -l`
CRIT48=`$GREP "Asymmetry * \: * (0| )\.55[0-9][0-9][0-9][0-9]" $log | wc -l`
CRIT49=`$GREP "S parameter * \: * 1\.00[0-9][0-9][0-9][0-9] Hz" $log | wc -l`
CRIT50=`$GREP "A parameter * \: * (0| )\.37[0-9][0-9][0-9][0-9] Hz" $log | wc -l`
CRIT51=`$GREP "Isotropic DSO contribution\: * (0| )\.16[0-9][0-9][0-9][0-9] Hz" $log | wc -l`
CRIT52=`$GREP "Isotropic PSO contribution\: * (\-0| \-)\.12[0-9][0-9][0-9][0-9] Hz" $log | wc -l`
CRIT53=`$GREP "Isotropic SD contribution \: * (0| )\.01[0-9][0-9][0-9][0-9] Hz" $log | wc -l`
CRIT54=`$GREP "Isotropic FC contribution \: * \-1\.72[0-9][0-9][0-9][0-9] Hz" $log | wc -l`
TEST[4]=`expr	$CRIT1 \+ $CRIT2 \+ $CRIT3 \+ $CRIT4 \+ $CRIT5 \+ $CRIT6 \+ \
		$CRIT7 \+ $CRIT8 \+ $CRIT9 \+ $CRIT10 \+ $CRIT11 \+ $CRIT12 \+ \
		$CRIT13 \+ $CRIT14 \+ $CRIT15 \+ $CRIT16 \+ $CRIT17 \+ $CRIT18 \+ \
		$CRIT19 \+ $CRIT20 \+ $CRIT21 \+ $CRIT22 \+ $CRIT23 \+ $CRIT24 \+ \
		$CRIT25 \+ $CRIT26 \+ $CRIT27 \+ $CRIT28 \+ $CRIT29 \+ $CRIT30 \+ \
		$CRIT31 \+ $CRIT32 \+ $CRIT33 \+ $CRIT34 \+ $CRIT35 \+ $CRIT36 \+ \
		$CRIT37 \+ $CRIT38 \+ $CRIT39 \+ $CRIT40 \+ $CRIT41 \+ $CRIT42 \+ \
		$CRIT43 \+ $CRIT44 \+ $CRIT45 \+ $CRIT46 \+ $CRIT47 \+ $CRIT48 \+ \
		$CRIT49 \+ $CRIT50 \+ $CRIT51 \+ $CRIT52 \+ $CRIT53 \+ $CRIT54`
CTRL[4]=92
ERROR[4]="SPIN-SPIN AVERAGE NOT CORRECT"

PASSED=1
for i in 1 2 3 4  
do
   if [ ${TEST[i]} -ne ${CTRL[i]} ]; then
     echo "${ERROR[i]} ( test = ${TEST[i]}; control = ${CTRL[i]} ); "
     PASSED=0
   fi
done

if [ $PASSED -eq 1 ]
then
  echo TEST ENDED PROPERLY
  exit 0
else
  echo THERE IS A PROBLEM
  exit 1
fi

%EOF%
#######################################################################
